package 力扣._290_单词规律;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

class Solution {
    public boolean wordPattern(String pattern, String s) {
        String[] words = s.split(" ");
        if (pattern.length() != words.length) return false;

        Map<Character, String> map = new HashMap<>();
        for(int i=0;i< words.length;i++){
            char c = pattern.charAt(i);
            String word = words[i];
            if(map.containsKey(c)){
                if(!map.get(c).equals(word))
                    return false;
            }else {
                // 检查下这个v是否有k对应，kv一一对应，不可一v对多k
                if (map.containsValue(word))
                    return false;
                map.put(c, word);

            }
        }
        return true;
    }
}